<template>
	<view class="container">
		<view class="cu-card" style="min-height: 500px;" v-if="userinfo.auth===0">
			<view class="reg_box">
				<view class="reg_box_bg"></view>
				<view class="cu-form-group margin-lr-lg border-b-line padding-0">
					<view class="title">姓名</view>
					<input data-key="name" focus placeholder="请输入" v-model="name" />
				</view>		
				<view class="cu-form-group margin-lr-lg border-b-line padding-0">
					<view class="title">身份证号</view>
					<input data-key="idcard"  placeholder="请输入" v-model="idcard" />
				</view>
				<view class="cu-form-group margin-lr-lg border-b-line padding-0">
					<view class="title">银行卡号</view>
					<input data-key="bankcard"  placeholder="请输入" v-model="bankcard" />
				</view>
			</view>
			<view class="cu-form-group margin-lr-lg padding-0 submit_btn">
				<button class="cu_btn" type="button" @click="updateData">立即认证</button>
			</view>
		</view>
		<view v-else class="realname" >
		<span>您已经通过了实名认证</span>
		</view>
	</view>
</template>

<script>
	import moveVerify from "@/components/moveVerify/moveVerify.vue"
	export default {
		components: {
			"move-verify":moveVerify
		},
		data() {
			return {
				resultData:{},
				name:'',
				idcard:'',
				bankcard:'',
				userinfo:[]
			};
		},
		
		onNavigationBarButtonTap(val) {
			if(this.userinfo.auth == 1){
				uni.showToast({
					title:"请勿重复实名",
					icon:"none"
				})
				return;
			}
			this.updateData();
		},
		onLoad: function (option) {
			this.helper.checkLogin();
			this.getData();
			
		},
		methods: {
			/* 校验成功的回调函数 */
			verifyResult(res){
				console.log(res);
				this.resultData = res;
			},
			/* 校验插件重置 */
			verifyReset(){
				this.$refs.verifyElement.reset();
				
				/* 删除当前页面的数据 */
				this.resultData = {};
			},
			getData:function(){
				//获取基础参数
				// uni.showLoading({
				// 	title:"数据加载中",
				// 	mask:true
				// })
				var info = uni.getStorageSync("userinfo");
				let timestamp = this.helper.now();
				let sign = this.helper.setSign(['username='+info.username,'token='+info.token,'timestamp='+timestamp]);
				this.helper.req({
					api:"getUserInfo",
					timestamp:timestamp,
					data:{username:info.username,token:info.token},
					header:{sign:sign},
					method:'GET',
				}).then(res=>{
					this.userinfo = res.data.data.userinfo;
					this.name = res.data.data.userinfo.name;
					this.idcard = res.data.data.userinfo.idcard;
					if(this.name == '无'){
						this.name = '';
					}
					if(this.idcard == '无'){
						this.idcard = '';
					}
					setTimeout(() => {
						uni.hideLoading();
					}, 300);
				})
			},
			updateData:function(){
				if(this.userinfo.auth == 1){
					uni.showToast({
						title:"请勿重复实名",
						icon:"none"
					})
					return;
				}
				if(this.name == ''){
					uni.showToast({
						title:"请输入您的真实姓名",
						icon:"none"
					})
					return;
				}
				if(this.idcard == ''){
					uni.showToast({
						title:"请输入您的身份证号码",
						icon:"none"
					})
					return;
				}
				if(this.bankcard == ''){
					uni.showToast({
						title:"请输入您的银行卡号",
						icon:"none"
					})
					return;
				}									
				//获取基础参数
				uni.showLoading({
					title:"数据更新中",
					mask:true
				})
				var info = uni.getStorageSync("userinfo");
				let timestamp = this.helper.now();
				let sign = this.helper.setSign(['name='+this.name,'idcard='+this.idcard,'bankcard='+this.bankcard,'timestamp='+timestamp,'token='+info.token]);
				this.helper.req({
					api:"certification",
					timestamp:timestamp,
					data:{name:this.name,idcard:this.idcard,bankcard:this.bankcard,token:info.token},
					header:{sign:sign},
					method:'POST',
				}).then(res=>{
					uni.hideLoading();
					
					uni.showModal({
						title: "提示",
						content:'实名认证更新成功',
						showCancel: false,
						confirmText: "确定",
						success:function(res){
							uni.redirectTo({
								url: "/pages/user/newuser"
							})
						}
					})
				})
			},
			//链接
			toUrl:function(e){
				uni.navigateTo({
					url: e,
				});	
			},
		},
	};
</script>

<style lang="scss">
	page {
		background-color: #ddeafd;
		height:100%;
	}
	.reset_title{
		font-size: 50upx;
		padding: 20upx;
	}
	.cu-form-group{
		background: none;
		height: 60px;
		
		input{
			color:#fff;
			text-align: right;
		}
	}
	.cu-form-group .title {
		min-width: 200upx;
		color: #fff;
	}
	.logo{
		padding: 80px 0 50px;
		text-align: center;
		image{
			width: 100px;
			height: 100px;
		}
	}
	.lg_img{
		width: 24px;
		height: 24px;
	}
	.reg_box{
		width: 88vw;
		margin: 6vw;
		padding: 8px 0;
		// background: #ffffff;
		border-radius: 6px;
		position: relative;
		
		.reg_box_bg{
			position: absolute;
			width: 100%;
			height: 100%;
			left: 0;
			top: 0;
			background-color: #38607f;
			opacity: 0.4;
			border-radius: 10px;
		}
	}
	.cu_btn{
		background: linear-gradient( 180deg, #50A7FF 0%, #3267FF 100%);
		height: 50px;
		width: 70vw;
		color: #fff;
		line-height: 50px;
		font-size: 16px;
		border-radius: 30px;
	}
	.realname{
		background: linear-gradient(180deg, #a0c4ff 0%, #4f8ffe 100%);
		margin: 20vw 10vw;
		color: #fff;
		text-align: center;
		line-height: 50px;
		font-size: 16px;
		border-radius: 30px;
	}
</style>
